﻿using System.Collections.ObjectModel;

namespace EduAssess.Services;

public static class ObservableCollectionExtensions
{
    public static ObservableCollection<T> Shuffle<T>(this ObservableCollection<T> collection)
    {
        var rnd = new Random();
        var count = collection.Count;

        for (var i = 0; i < count; i++)
        {
            var i1 = rnd.Next(count);
            var i2 = rnd.Next(count);

            (collection[i1], collection[i2]) = (collection[i2], collection[i1]);
        }

        return collection;
    }
}